#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-11-09 9:46 上午
# @Author  : yangdy
# @File    : 2020-11-07.327.区间和的个数
# @Software: PyCharmCE
from tools.my_methods import *


class Solution:
    def countRangeSum(self, nums: List[int], lower: int, upper: int) -> int:
        result, cur = 0, [0]
        for x in accumulate(nums):
            result += bisect_right(cur, x - lower) - bisect_left(cur, x - upper)
            insort(cur, x)
        return result

